package com.example.dto;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;

import java.io.IOException;
import java.util.Set;

public class AuthorizationGrantTypeSerializer extends JsonSerializer<Set<AuthorizationGrantType>> {

    @Override
    public void serialize(Set<AuthorizationGrantType> value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException {
        // 开始写入 JSON 数组
        gen.writeStartArray();
        for (AuthorizationGrantType method : value) {
            gen.writeString(method.getValue()); // 将每个 ClientAuthenticationMethod 转换为字符串
        }
        gen.writeEndArray(); // 结束 JSON 数组
    }
}